package com.hcss.core.common.filemgt.service;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hcss.core.common.filemgt.dao.AnnexFileDao;
import com.hcss.core.common.filemgt.model.AnnexFileModel;
import com.hcss.core.mvc.BaseService;
import com.hcss.core.util.FileUtil;



/**  
 *
 * @ClassName: AnnexService
 * @author: lvfang 
 * @date: 2014年2月24日 下午1:09:05
 * @version: V1.0  
 */
@Service("annexFileService")
public class AnnexFileService extends BaseService{
	@Autowired
	private AnnexFileDao annexFileDao;
	
	/**
	 * @Title: deleteUploadFile
	 * <p>删除附件<p>
	 * @param request
	 * @param fileId
	 * @return
	 * @return: boolean
	 */
	public boolean deleteUploadFile(HttpServletRequest request,int fileId){
		AnnexFileModel fileModel = annexFileDao.findById(fileId);
		//删除对应文件
		String fileRealPathDir = request.getSession().getServletContext().getRealPath("/upload"); 
		File removeFile = new File(fileRealPathDir+"/"+fileModel.getFileName());
		FileUtil.delFile(removeFile.getAbsolutePath());
		return annexFileDao.deleteFileById(fileId)>0?true:false;
	}
	
}
